﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using AB_SD_BusinessLogic;

namespace AB_SD_MockProject
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Headers["ForgotPassword"] != null)
            {
                string username = Request.Form["username"];
                string email = Request.Form["email"];
                string emailexpression = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";

                if (username == "" || email == "")                
                    Response.Write("<div class=\"validate-msg\">Please enter username and email!</div>");
                else
                    if (!Regex.IsMatch(email, emailexpression))
                        Response.Write("<div class=\"validate-msg\">Invalid email format!</div>");
                    else
                    {                        
                        if(!UserBUS.IsExist(username))
                            Response.Write("<div class=\"validate-msg\">Username is not exist!</div>");
                        else
                            if (!UserBUS.IsValidPasswordRequest(username, email))
                                Response.Write("<div class=\"validate-msg\">Username and email are not matched!</div>");
                            else
                                Response.Write("<div class=\"validate-msg\">Username and email are matched!</div>");
                    }
            }
        }
    }
}